import { Application } from "egg";
export interface Rules {
  type: string;
  format?: any;
  message: string;
}

export default (app: Application) => {
  const { validator } = app;
  validator.addRule("phone", (rule: Rules, value) => {
    const _regx = /^1[3-9]\d{9}$/;
    if (!_regx.test(value)) {
      return rule.message;
    }
  });
  validator.addRule("email", (rule: Rules, value) => {
    const _regx = RegExp(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/);
    if (!_regx.test(value)) {
      return rule.message;
    }
  });
};
